package com.echoesnet.echoesshortvideo.Activities;

import android.app.Activity;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;
import com.echoesnet.echoesshortvideo.AppController;
import com.echoesnet.echoesshortvideo.Beans.IncludeNavBarBean;
import com.echoesnet.echoesshortvideo.R;
import com.echoesnet.echoesshortvideo.Utils.ToastUtils;
import com.echoesnet.echoesshortvideo.View.EditViewWithCharIndicate;
import com.echoesnet.echoesshortvideo.ViewModels.FansFocusViewModel;
import com.echoesnet.echoesshortvideo.databinding.ActivityReportUserBinding;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class ReportUserActivity extends BaseActivity
{
    @BindView(R.id.tv_text_report)
    TextView tvTextReport;
    @BindView(R.id.tv_text_report_chooice)
    TextView tvTextReportChooice;
    @BindView(R.id.evw_input_report_user)
    EditViewWithCharIndicate evwInputReportUser;
    @BindView(R.id.tv_commit)
    TextView tvCommit;

    @BindView(R.id.tv_text_report_text)
    TextView tvTextReportText;
    private Unbinder unbinder;
    private Activity mAct;
    private String reason;
    private FansFocusViewModel uViewModel;
    private String uId;
    private ActivityReportUserBinding actBinding;
    private IncludeNavBarBean navBean;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        actBinding = DataBindingUtil.setContentView(this, R.layout.activity_report_user);
        navBean = new IncludeNavBarBean("举报用户", true);
        actBinding.relNavBar.setNavBean(navBean);
        actBinding.relNavBar.itvLeft.setOnClickListener(view -> finish());
        unbinder = ButterKnife.bind(this);
        initView();
    }

    private void initView()
    {
        mAct = this;
        reason = getIntent().getStringExtra("reason");
        uId = getIntent().getStringExtra("uId");
        tvTextReport.setText("举报理由：");
        tvTextReportText.setText(reason);
        uViewModel = ViewModelProviders.of(this).get(FansFocusViewModel.class);


    }

    @OnClick({R.id.tv_commit})
    public void onClick(View view)
    {
        switch (view.getId())
        {
            case R.id.tv_commit:

                uViewModel.reportUser().observe(this, new Observer<String>()
                {

                    @Override
                    public void onChanged(@Nullable String s)
                    {
                        //举报成功
                        finish();
                        ToastUtils.showShort("举报成功");
                        AppController.getInstance().clearTopActivity();


                    }
                });

                uViewModel.requestReportUser(uId,reason,evwInputReportUser.getInputText().toString().trim());
                break;
        }
    }
    @Override
    protected void onDestroy()
    {
        super.onDestroy();
        if (unbinder != null)
            unbinder.unbind();
    }
}
